<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var goodlist = [
            { id: 111, url: './images/g1.jpg', name: '美女1号', price: 1998, age: 20 },
            { id: 22, url: './images/g2.jpg', name: '美女2号', price: 1998, age: 20 },
            { id: 3456, url: './images/g3.jpg', name: '美女3号', price: 1998, age: 20 },
            { id: 4458, url: './images/g4.jpg', name: '美女4号', price: 1998, age: 20 },
            { id: 59877, url: './images/g1.jpg', name: '美女5号', price: 1998, age: 20 }
        ]
        var p = location.search;   //获取?id=111&name=美女1号  {id：111，name：'美女1号'}
        p = p.substring(1);   //截取的是？之后所有的字符
        var arr = p.split('=');  //['id','111']
        var obj = {};      //把数组转换成对象
        obj[arr[0]] = arr[1];  //{id：111}
        var res = goodlist.filter(function (item, index) {
            return item.id == obj.id;
        })
        //res就是根据id匹配=拿到的数据
        
    </script>
</body>

</html>